package com.king.platform.entity;

import com.king.platform.enmu.ResultEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BaseResult<T>
{
  private int code;

  private String message;

  private boolean status;

  private T data;

  public BaseResult(int code,String message,boolean status){
    this.code = code;
    this.message = message;
    this.status = status;
  }

  public BaseResult(int code,String message,boolean status,T data){
    this.code = code;
    this.message = message;
    this.status = status;
    this.data = data;
  }


  public BaseResult(ResultEnum result, boolean status,T data){
    this.code = result.getCode();
    this.message = result.getMessage();
    this.status = status;
    this.data = data;
  }

  public static <T> BaseResult<T> success(int code,String message){
    return new BaseResult<>(code,message,true);
  }

  public static <T> BaseResult<T> success(ResultEnum result){
    return new BaseResult<>(result.getCode(),result.getMessage(),true);
  }

  public static <T> BaseResult<T> success(ResultEnum result,T data){
    return new BaseResult<>(result.getCode(),result.getMessage(),true,data);
  }

  public static <T> BaseResult<T> failed(int code,String message){
    return new BaseResult<>(code,message,false);
  }

  public static <T> BaseResult<T> failed(ResultEnum result){
    return new BaseResult<>(result.getCode(),result.getMessage(),false);
  }

  public static <T> BaseResult<T> failed(ResultEnum result,T data){
    return new BaseResult<>(result.getCode(),result.getMessage(),false,data);
  }
}
